import request from "@/utils/request"
import type { Category, AttrInfo } from "@/api/product/attr/type"
import type { ResponseData } from "@/api/type"

// http://39.98.123.211:8510/swagger-ui.html
enum API {
    CATEGORY_1_URL = '/admin/product/getCategory1',
    CATEGORY_2_URL = '/admin/product/getCategory2/',
    CATEGORY_3_URL = '/admin/product/getCategory3/',
    ATTR_INFO_LIST_URL = '/admin/product/attrInfoList/',
    ATTR_INFO_SAVE_URL = '/admin/product/saveAttrInfo',
    ATTR_INFO_DELETE_URL = '/admin/product/deleteAttr/'
}

const getCategory1 = () => {
    return request.get<any, ResponseData<Category[]>>(API.CATEGORY_1_URL)
}

const getCategory2 = (id: number | undefined) => {
    return request.get<any, ResponseData<Category[]>>(API.CATEGORY_2_URL + `${id}`)
}


const getCategory3 = (id: number | undefined) => {
    return request.get<any, ResponseData<Category[]>>(API.CATEGORY_3_URL + `${id}`)
}

const getAttrInfoList = (category1Id: number | undefined, category2Id: number | undefined, category3Id: number | undefined) => {
    return request.get<any, ResponseData<AttrInfo[]>>(API.ATTR_INFO_LIST_URL + `${category1Id}/${category2Id}/${category3Id}`)
}

const saveAttrInfo = (attrInfo: AttrInfo) => {
    return request.post<any, ResponseData<AttrInfo>>(API.ATTR_INFO_SAVE_URL, attrInfo)
}

const deleteAttrInfo = (id: number) => { 
    return request.delete<any, ResponseData<String>>(API.ATTR_INFO_DELETE_URL + `${id}`)
}

export {
    getCategory1,
    getCategory2,
    getCategory3,
    getAttrInfoList,
    saveAttrInfo,
    deleteAttrInfo
}